class Admin::BlogController < Base::BlogBaseController
  before_filter :login_required
  layout "admin"
  
  uses_tiny_mce(:options => {
      #This option should contain a comma separated list of 
      #element id's to convert into editor instances. 
      #This option is only used if mode is set to "exact".
      :mode=>'exact',
      :elements=>'blog_content',
      :theme => 'advanced',
      :browsers => %w{msie gecko},
      :language=>"en",
      :theme_advanced_toolbar_location => "top",
      :theme_advanced_toolbar_align => "left",
      :theme_advanced_resizing => true,
      :theme_advanced_resize_horizontal => false,
      :paste_auto_cleanup_on_paste => true,
      :theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect},
      :theme_advanced_buttons2 => %w{bold italic underline strikethrough separator 
        justifyleft justifycenter justifyright indent outdent 
        separator bullist numlist forecolor backcolor},
      :theme_advanced_buttons3 =>%w{link unlink image undo redo},
      :plugins => %w{contextmenu paste}},
    :only => [:new, :edit, :show, :index])
    
  def new
    @blog=Blog.new
    @categories=Category.find(:all,:order=>"name")
  end
  
  def create
    @blog=Blog.new(params[:blog])
    @blog.save
    redirect_to :action=>:index
  end
  
  def delete
    @blog=Blog.find(params[:id])
    @blog.destroy
    redirect_to :action=>:index
  end
  
  def edit
    @categories=Category.find(:all,:order=>"name")
    @blog=Blog.find(params[:id])
  end
  
  def update
    blog=Blog.find(params[:id])
    @categories=Category.find(:all,:order=>"name")
    if blog.update_attributes(params[:blog]) 
      redirect_to :action=>:index
    else
      redirect_to :action=>:edit
    end
  end
  
  def delete_comment
    @blog=Blog.find(params[:id])
    comment=Comment.find(params[:comment_id])
    comment.destroy
    redirect_to :action=>:view, :id=>@blog.id
  end
  
end